
function init(){
	$("#grid").kendoGrid({
	     dataSource: {
	         type: "json",
	         transport: {
	        	 read: {
	                 url: urlSearch,
	                 dataType: "json",
	                 type: "get",
	                 data : {}
	             },
	         },
	         //pageSize: 10,
	         schema:{
		        data: "list",
		        total: function(data) {
	                return data.total;
	            },
	    	 },
	    	 requestStart: function(e) {   
                e.sender.transport.options.read.data = utils.getParamsForSearch("frmSearch");
             },
    	     pageSize: 20,
    	     serverPaging: true,
	     },	    
	     sortable: false,         
         groupable: false,
         pageable: {
             refresh: true,
             //pageSizes: true,
         },
	     columns: [{
	         field: "time",
	         title: "Time",
	         width: 80
	     }, {
	         field: "appName",
	         title: "Application",
	         width: 70
	     },{
	         field: "type",
	         title: "Type",
	         width: 80,
	         template: function(record)
	         {
	        	 if(record.type == 1) return "DLog -> DLake";
	        	 else if(record.type == 2) return "DLake -> DWH";
	        	 else if(record.type == 3) return "DWH -> DM";
	         }
	     },{
	         field: "actionName",
	         title: "Script",
	         width: 140
	     },{
	         field: "startTime",
	         title: "Start",
	         width: 100
	     },{
	         field: "endTime",
	         title: "End",
	         width: 100
	     },{
	         field: "status",
	         title: "Status",
	         width: 100,
	         template: function(record)
	         {
	        	 if(record.status == 0) return "Waiting";
	        	 else if(record.status == 1) return "Ready";
	        	 else if(record.status == 2) return "Running";
	        	 else if(record.status == 3) return "Error";
	        	 else return "Finish";
	         }
	     }], 
	     dataBound : function(e){
	    	// Tô xanh những line đang running
	    	var grid = $("#grid").data("kendoGrid");
    	    var dataView = e.sender.dataSource.view();
    	    var currenRow = null; 
    	    
    	    
	    	for(var i = 0; i < dataView.length; i++) {
	    		var currentUid = dataView[i].uid;
	    		
			    if(dataView[i].status === 2) {
			    	currenRow = grid.table.find("tr[data-uid='" + currentUid + "']");
		            $(currenRow).addClass("grid-selected");
			    }
			    else if(dataView[i].status === 3)
			    {
			    	currenRow = grid.table.find("tr[data-uid='" + currentUid + "']");
		            $(currenRow).addClass("grid-alert");
			    }
			}
	     }
	});
}

function setAutoRefreshGrid(second)
{
	if(typeof(second) == "undefined")
		second = 10;
		
	setInterval(function(){
		$("#grid").data("kendoGrid").dataSource.read();
	}, second * 1000);
}

function search(){
	$("#grid").data("kendoGrid").dataSource.read();	// Reset grid
	
}